<template>
  <div id="forget">
    <forget-nav-bar />
    <forget-main
      :captcha-address="captchaAddress"
      @handleChangePassword="handleChangePassword"
    />
  </div>
</template>

<script>
import ForgetNavBar from "./childComps/ForgetNavBar";
import ForgetMain from "./childComps/ForgetMain";

import { getCaptchas } from "network/login";
import { getChangePassword } from "network/forget";
export default {
  data() {
    return {
      captchaAddress: "",
    };
  },
  created() {
    this.getCaptchas();
  },
  mounted() {
    this.$bus.$on("handleImgBarter", () => {
      this.getCaptchas();
    });
  },
  methods: {
    // 验证码
    getCaptchas() {
      getCaptchas().then((res) => {
        this.captchaAddress = res.code;
      });
    },
    getChangePassword(data) {
      getChangePassword(data).then((res) => {
        let tips = res.status ? res.success : res.message;
        this.$toast.handleTipsText(tips);
        res.status === 0 ? this.getCaptchas() : "";
      });
    },
    handleChangePassword(data) {
      this.getChangePassword(data);
    },
  },
  components: {
    ForgetNavBar,
    ForgetMain,
  },
};
</script>
<style lang="less" scoped>
#forget {
  position: relative;
  height: 100vh;
  background-color: #f5f5f5;
  z-index: 1;
}
</style>